package com.fairytask.ui.login
{
	import com.fairytask.engine.components.button.Button;
	import com.fairytask.engine.components.clip.Clip;
	import com.jzonl.event.LoginEvent;
	import com.fairytask.ui.base.FrameUI;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.net.SharedObject;

	/**
	 * 登陆界面 
	 * @author hanjy
	 */	
	public class LoginUI extends FrameUI
	{
		public static var instance	:LoginUI	=	null;
		
		public var login_bg	:Clip;
		public var nameMC		:Clip;
		public var nameInput	:MovieClip;
		public var loginBtn	:Button;
		private var _sharedObj	:SharedObject; //保存用户名
		
		public function LoginUI(popUI:Boolean=false)
		{
			super(popUI);
		}
		
		/**
		 * 取得单例 
		 * @return 
		 * 
		 */
		public static function getInstance():LoginUI
		{
			if(null==instance)
			{
				instance	=	new LoginUI();
			}
			return instance;
		}
		
		/**
		 * 重写显示 
		 * 
		 */
		override public function initGUI():void
		{
			try
			{
				_sharedObj=SharedObject.getLocal("s2.jzonl.com");
			}
			catch (e:Error)
			{
				
			}
			//填写的用户名和密码
			if (_sharedObj.data.username && _sharedObj.data.username!="")
			{
				nameInput.username.text=getSharedObj();
			}
			//			lo
			initEvent();
		}
		
		/**
		 * 事件处理 
		 * 
		 */
		private function initEvent():void
		{
			loginBtn.addEventListener(MouseEvent.CLICK, onLogin);
		}
		
		/**
		 * 当点击登陆按钮 
		 * @param evt
		 * 
		 */
		private function onLogin(evt:MouseEvent):void
		{
			//判断用户名和密码是否为空
			if (nameInput.username.text != "")
			{
				model.dispatchEvent(new LoginEvent(LoginEvent.CLICK_LOGIN,[nameInput.username.text]));
				setSharedObj(nameInput.username.text);
			}
		}
		
		//取存入用户名
		private function getSharedObj():String
		{
			return _sharedObj.data["username"];
		}
		
		//存入数据
		private function setSharedObj(val:*):void
		{
			_sharedObj.data["username"]=val;
		}
		
		/**
		 * 重写显示 
		 * @param space
		 * @param onshow
		 * @param argc
		 * 
		 */
		override public function show(space:String=LOGINLAYER, onshow:Function=null):void
		{
			super.show(space,onshow);
		}
	}
}